package com.example.myinput;

import android.graphics.PointF;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class TrajectoryGenerator {
    private static final Random random = new Random();
    private static float randnBm() {
        double u = 0, v = 0;
        while (u == 0) u = random.nextDouble();
        while (v == 0) v = random.nextDouble();
        return (float)(Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v));
    }
    public static List<PointF> randomPoints(float x1, float y1, float x2, float y2,
                                            int nums){
        List<PointF> array = new ArrayList<>();
        array.add(new PointF(x1, y1));
        float dx=x2-x1;
        float dy=y2-y1;
        System.out.println("dx:"+dx+",dy:"+dy);
        for(int i=0;i<nums;i++){
            float moveRatio=((float)i + 1) /(float)nums;
            float jitterX= randnBm()*2;
            float jitterY=randnBm()*1;
            float baseX=x1+dx*moveRatio;
            float baseY=y1+dy*moveRatio;
            array.add(new PointF(Math.max(0,baseX + jitterX), Math.max(0,baseY + jitterY)));
        }
        array.add(new PointF(x2,y2));
        return array;
    }
}
